#include <stdio.h>

#ifndef MUK_LOG
#define MUK_LOG

#define LEVEL_ERROR 0
#define LEVEL_WARNING 1
#define LEVEL_INFO 2
#define LEVEL_DEBUG 3

#ifdef LOG_MODULE_LEVEL
#define LOG_DEFAULT_LEVEL LOG_MODULE_LEVEL
#else
#ifndef LOG_DEFAULT_LEVEL
#define LOG_DEFAULT_LEVEL LEVEL_WARNING
#endif
#endif

#ifndef LOG_MODULE
#define LOG_MODULE "log"
#endif

/**
 * Function prototype for syncronized log text, Recommed using below brief API
 * LOG_XXX instead of this.
 *
 * @param[in]  log_level      Serverity of Log
 * @param[in]  mod            Module name
 * @param[in]  fmt, ...       Variable Parameter, support format print to log
 *
 * @return  0 on success, negative error on failure.
 */
void log(unsigned char log_level, unsigned char default_level, char *mod,
         char *fmt, ...);

#define LOG_ERROR(mod, ...)                                                    \
    log(LEVEL_ERROR, LOG_DEFAULT_LEVEL, (char *)(mod), __VA_ARGS__)
#define LOG_WARNING(mod, ...)                                                  \
    log(LEVEL_WARNING, LOG_DEFAULT_LEVEL, (char *)(mod), __VA_ARGS__)
#define LOG_INFO(mod, ...)                                                     \
    log(LEVEL_INFO, LOG_DEFAULT_LEVEL, (char *)(mod), __VA_ARGS__)
#define LOG_DEBUG(mod, ...)                                                    \
    log(LEVEL_DEBUG, LOG_DEFAULT_LEVEL, (char *)(mod), __VA_ARGS__)

#endif